package learn.java.jetty;

import java.util.Collections;
import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.Filter;

import org.eclipse.jetty.quickstart.QuickStartConfiguration;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlets.DoSFilter;
import org.eclipse.jetty.servlets.WelcomeFilter;
import org.eclipse.jetty.webapp.WebAppContext;

/**
 * @author suzheng
 * @date 2021-05-08
 **/
public class App {
    public static void main(String[] args) throws Exception {
        Server server = new Server(8080);
        WebAppContext webAppContext = new WebAppContext();

        ServletHolder holder = new ServletHolder();
        holder.setName("default");
        holder.setClassName("org.eclipse.jetty.servlet.DefaultServlet");
        holder.setInitParameter("dirAllowed", "false");
        holder.setInitOrder(1);
        webAppContext.getServletHandler().addServletWithMapping(holder, "/");
        webAppContext.getServletHandler().getServletMapping("/").setDefault(true);
        webAppContext.addFilter(WelcomeFilter.class,"/", EnumSet.of(DispatcherType.REQUEST));
        webAppContext.configure();
        server.setHandler(webAppContext);
        server.start();
        server.join();
    }

}
